package main

import (
	"fmt"
	"sync"
)

func send(sech chan int) {
	for i := 1; i < 2000; i++ {
		sech <- i
	}
	close(sech)
}

func read(sech chan int, resch chan [2]int) {
	var waite sync.WaitGroup
	waite.Add(8)
	for i := 0; i < 8; i++ {
		go func() {
			defer waite.Done()
			for {
				n, ok := <-sech
				if !ok {
					return
				}
				data := 0
				for i := 1; i <= n; i++ {
					data += i
				}
				resch <- [2]int{n, data}
			}
		}()
	}
	waite.Wait()
	close(resch)

}

func main() {

	sendChan := make(chan int)
	resChan := make(chan [2]int)
	go send(sendChan)

	go read(sendChan, resChan)

	for {
		data, ok := <-resChan
		if !ok {
			break
		}
		fmt.Println(data)
	}
}
